import { axios } from "../../utils/request"
import Toast from '@vant/weapp/toast/toast';
// pages/comment/comment.ts
Page({
  /**
   * 页面的初始数据
   */
  data: {
    initData:{} as any,
    info:""
  },
  async comment(){
    let info = this.data.info
    let room = this.data.initData.roomId
    let order = this.data.initData.id
    if(info){
      try {
          await axios("/comment","POST",{info, room,order})
          Toast({
            type: 'success',
            message: '提交成功',
            onClose: () => {
              wx.redirectTo({
                url:"/pages/order/order"
              })
            },
          }); 
      } catch (error) {
        Toast({
          type: 'fail',
          message: '提交失败'
        }); 
      }
    }else{
      Toast({
        type: 'fail',
        message: '请先填写评论'
      }); 
    }
  },
  inputChange(e:any){
    let info = e.detail.value
    this.setData({
      info
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
    const eventChannel = this.getOpenerEventChannel()
    eventChannel.on('context', (data)=> {
      data.createTime =  data.createTime.substring(0,10)
        this.setData({
          initData:data,
        })
    })
  }
})